<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMessagesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 消息表
        Schema::create('messages', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('ID');
            $table->string('title')->default('')->comment('消息标题');
            $table->string('type')->default(1)->comment('类型');
            $table->text('content')->nullable()->comment('内容');
            $table->bigInteger('employees_id')->nullable()->comment('员工ID');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('修改时间');
            $table->timestamp('deleted_at')->nullable()->comment('删除时间');
            $table->bigInteger('created_admin_id')->default(0)->comment('创建人ID');
            $table->bigInteger('updated_admin_id')->default(0)->comment('修改人ID');
        });

        DB::statement('alter table' . ' ' . config('database.connections.mysql.prefix', '') . 'messages comment "消息表"');

        // 用户消息表
        Schema::create('user_messages', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('ID');
            $table->tinyInteger('message_type')->default(1)->comment('消息类型[1:系统消息]');
            $table->tinyInteger('status')->default(0)->comment('消息状态[0:未读,1:已读,2:删除]');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('修改时间');
            $table->timestamp('deleted_at')->nullable()->comment('删除时间');
            $table->bigInteger('employees_id')->nullable()->comment('员工ID');
            $table->unsignedBigInteger('message_id')->nullable()->comment('消息ID');
        });

        DB::statement('alter table' . ' ' . config('database.connections.mysql.prefix', '') . 'user_messages comment "用户消息表"');

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('messages');                   // 消息表
        Schema::dropIfExists('user_messages');              // 用户消息表
    }
}
